<?php
    require_once( dirname(__FILE__) . "/../../../libs/GeoIP/GeoIP.php" );

    class GeoIP
    {
        /**
         * Net_GeoIP instance
         * 
         * @var Net_GeoIP
         */
        private static $gi;

        private function  __construct()
        {
            
        }
        
        private function __clone()
        {
        }

        private static function GetGeoIp()
        {
            if ( !( self::$gi instanceof Net_GeoIP) )
            {
                self::$gi = Net_GeoIP::getInstance(GEOIP_DB);
            }

            return self::$gi;
        }

        /**
         *
         * @param string $ipAddress
         * @return string 2-letter ISO country code
         */
        public static function GetCountryCode( $ipAddress )
        {
            $country = '';
            try
            {
                $country = self::GetGeoIp()->lookupCountryCode($ipAddress);
            }
            catch (Exception $e)
            {
            }

            return $country;
        }
        
        /**
         *
         * @param string $ipAddress
         * @return string country Name
         */
        public static function GetCountryName($ipAddress)
        {
            $country = '';
            try
            {
              $country = self::GetGeoIp()->lookupCountryName($ipAddress);
            }
            catch (Exception $e)
            {
            }
            return $country;
        }
    }
?>
